package com.mrobuy.jdvc.controller;

import com.mrobuy.jdvc.Result;
import com.mrobuy.jdvc.dao.VCProductCreateDao;
import com.mrobuy.jdvc.entity.VCProductCreateTask;
import com.mrobuy.util.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ProductCreateController {

	@Autowired
	private VCProductCreateDao vcProductCreateDao;

	@RequestMapping("/productcreate")
	public String productcreate(Model model) {
		return "productcreate";
	}


	@RequestMapping("/productcreate/query")
	@ResponseBody
	public Object query(HttpServletRequest request, VCProductCreateTask condition) {

		int start = ServletRequestUtils.getIntParameter(request, "start", 1);
		int length = ServletRequestUtils.getIntParameter(request, "length", 10);

		int draw = ServletRequestUtils.getIntParameter(request, "draw", 1);


		Pagination pagination = vcProductCreateDao.load(start, length, condition);

		//int offset = page*pagesize - pagesize;
		pagination.setDraw(draw);

		return pagination;
	}


	@RequestMapping("/productcreate/add")
	@ResponseBody
	public Result add(HttpServletRequest request, VCProductCreateTask record) {

		Result result = vcProductCreateDao.insert(record);

		return result;
	}

}
